package com.ecelin.controller;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.ecelin.entity.UserInfo;
import com.ecelin.service.UserInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserInfoController {

    private final UserInfoService userInfoService;

    @GetMapping
    public List<UserInfo> getUserInfo() {
        List<UserInfo> list = userInfoService.list();
        return list;
    }

    @PostMapping("add")
    public UserInfo addUserInfo(@RequestBody UserInfo userInfo) {
        userInfo.setId(IdWorker.getId(UserInfo.class));
        userInfoService.save(userInfo);
        return userInfo;
    }
}
